package com.blog.util.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * @author cgx
 * @Date 2021/8/15 19:52
 *
 * Dto工具类
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AjaxResult {

    /**
     * 返回处理状态
     */
    private Boolean state;
    /**
     * 返回的提示信息
     */
    private String msg;

    /**
     * 返回的数据
     */
    private Object data;

    /**
     * redis 返回的type
     */
    private String type;


    /**
     * 返回处理状态和信息
     * @param
     * @return
     */
    public static AjaxResult error(String msg) {
        AjaxResult dto = new AjaxResult();
        dto.setState(false);
        dto.setMsg(msg);
        return dto;
    }

    /**
     * 返回处理状态
     * @param
     * @return
     */
    public static AjaxResult success() {
        AjaxResult dto = new AjaxResult();
        dto.setState(true);
        return dto;
    }
    /**
     * 返回处理状态和数据
     * @param
     * @return
     */
    public static AjaxResult success(Object data) {
        AjaxResult dto = new AjaxResult();
        dto.setState(true);
        dto.setData(data);
        return dto;
    }

    /**
     * 返回错误处理请求，只返回状态
     * @param
     * @return
     */
    public static AjaxResult error() {
        AjaxResult dto = new AjaxResult();
        dto.setState(false);
        return dto;
    }



    public static AjaxResult success(Object data,String type) {
        AjaxResult dto = new AjaxResult();
        dto.setState(true);
        dto.setData(data);
        dto.setType(type);
        return dto;
    }
}
